package com.learn.annotation_config.configuration;

import com.learn.annotation_config.configuration.imports.ImportBeanDefinitionRegistrarImpl;
import com.learn.annotation_config.configuration.imports.ImportConfiguration1;
import com.learn.annotation_config.configuration.imports.ImportSelectorImpl;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

/**
 * @Configurable：将类标记为配置类，其作用相当于XML配置文件
 * @ComponentScan：扫描@Component注解配置
 * @PropertySource：加载外部properties资源配置
 * @Profile：配置环境
 * @Import：导入其他配置类
 */
@Configurable
@ComponentScan("com.learn.annotation_config.configuration")
@PropertySource("classpath:application.properties")
// @Profile("test")
@Import({ImportConfiguration1.class, ImportSelectorImpl.class, ImportBeanDefinitionRegistrarImpl.class})
public class ConfigurationApplication {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigurationApplication.class);
        System.out.println(applicationContext.getBean("dataSource"));
        System.out.println(applicationContext.getBean("connection"));
        System.out.println(applicationContext.getBean("formatDate"));
    }
}
